NAME	= test
CC      = sdcc
CFLAGS  = -I./INCLUDE -c --stack-auto
LFLAGS  = --code-loc 0x2100 --xram-loc 0x6000 --stack-auto --stack-loc 0x80 

PROJECT  = $(shell cat PROJECT)
VERSION  = $(shell cat VERSION)
BUILD    = $(shell cat BUILD)
TYPE     = $(shell cat TYPE)

PROJNAME = ${PROJECT}-${VERSION}-${BUILD}-${TYPE}
TARBALL  = ${PROJNAME}.tar

M3P		 = m3p
COMPORT	 = /dev/cu.usbserial
COMLOG	 = $(COMPORT)_log.txt
BAUD	 = 9600	

SRC_DIR = SRC

all: test

clean:
	rm -f  $(NAME).hex \
			$(NAME).bin \
			$(NAME).map \
			$(NAME).mem \
			$(NAME).lnk \
			pm3p_*.txt \
			com?_log.txt \
			$(TARBALL).gz \
			$(SRC_DIR)/*.asm \
			$(SRC_DIR)/*.rel \
			$(SRC_DIR)/*.rst \
			$(SRC_DIR)/*.sym \
			$(SRC_DIR)/*.lst 
load:
	$(M3P) lfile load.m3p


dist:
	tar cvf $(TARBALL) *
	gzip $(TARBALL)

term:
	$(M3P) echo $(COMLOG) $(BAUD) openchannel $(COMPORT) +echo 6 term -echo bye


LIST_SRC = \
$(SRC_DIR)/interrupt.c \
$(SRC_DIR)/rs232.c \
$(SRC_DIR)/keyboard.c \
$(SRC_DIR)/max.c \
$(SRC_DIR)/led.c \
$(SRC_DIR)/fifo.c \
$(SRC_DIR)/repl.c \
$(SRC_DIR)/test.c

LIST_OBJ = $(LIST_SRC:.c=.rel)

test : $(LIST_OBJ) makefile
	$(CC) $(LIST_OBJ) -o test.hex $(LFLAGS)
	$(M3P) hb166 test.hex test.bin bye


$(LIST_OBJ) : %.rel : %.c makefile
	$(CC) -c $(CFLAGS) $< -o $@  
